package com.yf1706.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yf1706.bean.User;
import com.yf1706.dao.jpa.IUserJDAO;
import com.yf1706.dao.mybatis.IUserMDAO;
import com.yf1706.vo.UserEmpDepVO;

@Service
@Transactional(rollbackFor=Exception.class)
public class UserService {
	@Autowired
	private IUserJDAO ujdao;
	@Autowired
	private IUserMDAO umdao;
	
	public User login(int userId,String psw) {
		return  ujdao.findByUserIdAndPassword(userId,psw);
	}
	
	//查询所有用户
	public List<User> findAllUser(){
		return (List<User>) ujdao.findAll();
	}
	
	//查询所有用户的基本信息
	public List<UserEmpDepVO> fundUserBasic(){
		List<Object[]> list= ujdao.fundUserBasic();
		List<UserEmpDepVO> ueds=new ArrayList<UserEmpDepVO>();
		for(Object[] objs:list) {
			System.out.println(Arrays.toString(objs));
			UserEmpDepVO ued=new UserEmpDepVO(Integer.parseInt(objs[0].toString()), 
					(String)objs[1], Integer.parseInt(objs[2].toString()), (String)objs[3]);
			ueds.add(ued);
		}
		return ueds;
	}
	
	//根据id查询用户的基本信息
	public UserEmpDepVO fundUserBasicByUserId(int userId){
		List<Object[]> objList= ujdao.fundUserBasicByUserId(userId);
		Object[] objs=objList.get(0);
		System.out.println((Integer)objs[0]);
		UserEmpDepVO ued=new UserEmpDepVO((Integer)objs[0], 
				(String)objs[1], (Integer)objs[2], (String)objs[3]);
		return ued;
	}
		
}
